The QRCode module provides functionality for parsing, generating, and scanning QR codes. Scripts can use this module to decode QR codes from images, generate QR code images from text, or open the system scanning interface to scan a QR code.
This module is suitable for the following scenarios:
- Parsing QR code content from a local image file
- Parsing QR codes from a
UIImageobject - Generating a QR code image from text
- Opening the scanning interface to scan a QR code
All methods are asynchronous APIs and return a Promise.
API
parse
Parse a QR code from an image file at the specified path.
This method reads the image file at the specified path and attempts to recognize the QR code contained in the image.
If a QR code is successfully decoded, the text content embedded in the QR code is returned. If no QR code is detected or parsing fails, the method returns null.
Example
parseImage
Parse a QR code from a UIImage object.
This method parses a QR code directly from an in-memory image object without requiring the image to be saved to a file first.
Example
generate
Generate a QR code image from text.
This method encodes the specified text into a QR code and returns the generated QR code image.
Example
scan
Open the scanning interface and scan a QR code.
This method opens the QR code scanning interface and uses the device camera to scan a QR code.
When the scan succeeds, the text content embedded in the QR code is returned.
If the user cancels the scan or no QR code is recognized, the method returns null.
